<?php

/**
 * Description of feed_bank
 *
 * @author phuchv
 */
require APPPATH . 'libraries/simple_html_dom.php';

class feed_bank {

    public function do_feed_gold() {
        $data = simplexml_load_file(realpath(APPPATH) . "/data/gold/gold_eximbank.xml");
        $i = 0;
        foreach ($data->gold as $gold) {
            if ($i % 2 == 0) {
                $arr["buy1"] = (string) $gold->buy;
                $arr["sell1"] = (string) $gold->sell;
            } else {
                $arr["buy2"] = (string) $gold->buy;
                $arr["sell2"] = (string) $gold->sell;
            }
            $i++;
        }
        return $arr;
    }

    public function do_feed_exchange_rate() {
        $data = simplexml_load_file(realpath(APPPATH) . "/data/exrate/exrate.xml");
        $arr["datetime"] = (string) $data->datetime;
        foreach ($data->exrate as $exrate) {
            $ex['currencycode'] = (string) $exrate['currencycode'];
            $ex['buy'] = (float) $exrate['buy'];
            $ex['sell'] = (float) $exrate['sell'];
            $arr_exrate[] = $ex;
        }
        $arr["exrate"] = $arr_exrate;
        return $arr;
    }

}
?>
